package com.coincalf.service.impl;

import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.baomidou.mybatisplus.plugins.Page;
import com.baomidou.mybatisplus.service.impl.ServiceImpl;
import com.coincalf.entity.DigitalEncyclopedia;
import com.coincalf.mapper.DigitalEncyclopediaMapper;
import com.coincalf.service.DigitalEncyclopediaService;
import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils;

@Service
public class DigitalEncyclopediaServiceImpl extends ServiceImpl<DigitalEncyclopediaMapper, DigitalEncyclopedia> implements DigitalEncyclopediaService {

    @Override
    public Page<DigitalEncyclopedia> queryByCategory(String category, Integer pageNo, Integer pageSize) {
        EntityWrapper<DigitalEncyclopedia> wrapper = new EntityWrapper<>();
        wrapper.eq("status", 1);
        if (!StringUtils.isEmpty(category)) {
            wrapper.eq("category", category.trim());
        }
        wrapper.orderBy("sort", true).orderBy("created", false);
        Page<DigitalEncyclopedia> page = new Page<>();
        page.setCurrent(pageNo).setSize(pageSize);
        return super.selectPage(page, wrapper);
    }

}
